const express = require('express');

const router = express.Router();
const Mock = require('mockjs');

router.get('/ajax', function (req, res) {
  res.setHeader('Access-Control-Allow-Origin', '*');
  res.status(200).json(
    Mock.mock({
      id: /\d{6}/,
      name: '@cname',
      username: '@last',
      age: '@integer(3,20)',
      deptId: /\d{6}/,
    }),
  );
});

router.get('/userData', function (req, res) {
  res.setHeader('Access-Control-Allow-Origin', '*');
  res.status(200).json(
    Mock.mock({
      data: {
        id: /\d{6}/,
        name: '@cname',
        username: '@last',
        age: '@integer(3,20)',
        deptId: /\d{6}/,
      },
    }),
  );
});

router.get('/postData', function (req, res) {
  res.setHeader('Access-Control-Allow-Origin', '*');
  res.status(200).json(
    Mock.mock({
      data: {
        id: /\d{6}/,
        title: '@ctitle',
        content: '@cparagraph',
      },
    }),
  );
});

module.exports = router;
